//
//  UIButton+Extensions.swift
//  新浪微博
//
//  Created by zj on 2017/10/12.
//  Copyright © 2017年 zj. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(title: String, fontSize: CGFloat = 16, normalColor: UIColor = UIColor.orange, highlightedColor: UIColor =  UIColor.black, backgroundImageName: String? = nil) {
        self.init()
        
        setTitle(title, for: UIControlState.normal)
        titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        setTitleColor(normalColor, for: UIControlState.normal)
        setTitleColor(highlightedColor, for: UIControlState.highlighted)
        
        if let imageName = backgroundImageName {
            setBackgroundImage(UIImage.init(named: imageName), for: UIControlState.normal)
            setBackgroundImage(UIImage.init(named: imageName + "_highlighted"), for: UIControlState.highlighted)
        }
        
        sizeToFit()
    }
}
